package com.aipp.mall.h5.controller;

import com.aipp.mall.common.anno.Note;
import com.aipp.mall.common.utils.Result;
import com.aipp.mall.common.utils.SecurityUtil;
import com.aipp.mall.h5.domain.entity.Feedback;
import com.aipp.mall.h5.domain.vo.AreaVO;
import com.aipp.mall.h5.mapper.FeedbackMapper;
import com.aipp.mall.h5.service.H5CommonService;
import com.aipp.mall.h5.service.SysConfigService;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 公共接口
 * @author cc
 */
@RestController
@RequestMapping
public class H5CommonController {

    //  @Resource
//  private OssUtils ossUtils;

    @Resource
    private SysConfigService sysConfigService;

    @Resource
    private H5CommonService h5CommonService;

    @Resource
    private FeedbackMapper feedbackMapper;

    @Note("新增意见反馈")
    @PostMapping("/h5/feedback/create")
    public ResponseEntity<Integer> add(@RequestBody Feedback feedback) {
        feedback.setCreateTime(LocalDateTime.now());
        feedback.setCreateBy(SecurityUtil.getLocalMember().getId());
        feedback.setHandleStatus(0);
        return ResponseEntity.ok(feedbackMapper.insert(feedback));
    }

    @GetMapping("/h5/area")
    public Result<List<AreaVO>> getAreaList() {
        return  Result.ok(h5CommonService.getAreaList());
    }

    @PostMapping("/h5/file/upload")
    public Result<String> uploadFile(MultipartFile file) {
        // String url = ossUtils.uploadOneFile(file);
        return Result.ok("url");
    }

    @GetMapping("/no-auth/config/get")
    public Result<String> getSysConfig(String configKey) {
        String s = sysConfigService.selectConfigByKey(configKey);
        return Result.ok(s);
    }

}
